package com.ruoyi.project.agvQuene.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.agvQuene.domain.AgvExecution;
import com.ruoyi.project.agvQuene.service.IAgvExecutionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * AGV/CTU执行队列Controller
 *
 * @author ruoyi
 * @date 2025-04-14
 */
@Controller
@RequestMapping("/system/execution")
public class AgvExecutionController extends BaseController {
    private String prefix = "system/execution";

    @Autowired
    private IAgvExecutionService agvExecutionService;

    @GetMapping()
    public String execution() {
        return prefix + "/execution";
    }

    /**
     * 查询AGV/CTU执行队列列表
     */
    @RequiresPermissions("system:execution:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AgvExecution agvExecution) {
        if (agvExecution.getIsFinish() == 1) {
            startPage();
            List<AgvExecution> list = agvExecutionService.selectAgvExecutionList(agvExecution);
            return getDataTable(list);
        } else {
            startPage();
            List<AgvExecution> list = agvExecutionService.selectAgvExecutionListFinish(agvExecution);
            return getDataTable(list);
        }

    }


    @RequestMapping("/reload")
    @ResponseBody
    public AjaxResult reload(@RequestParam("guids") String[] guids) {
        for (String s : guids) {
            agvExecutionService.updateReload(s);
        }
        return AjaxResult.success("操作成功");

    }

    /**
     * 导出AGV/CTU执行队列列表
     */
    @RequiresPermissions("system:execution:export")
    @Log(title = "AGV/CTU执行队列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AgvExecution agvExecution) {
        List<AgvExecution> list = agvExecutionService.selectAgvExecutionList(agvExecution);
        ExcelUtil<AgvExecution> util = new ExcelUtil<AgvExecution>(AgvExecution.class);
        return util.exportExcel(list, "AGV/CTU执行队列数据");
    }

    /**
     * 新增AGV/CTU执行队列
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存AGV/CTU执行队列
     */
    @RequiresPermissions("system:execution:add")
    @Log(title = "AGV/CTU执行队列", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AgvExecution agvExecution) {
        return toAjax(agvExecutionService.insertAgvExecution(agvExecution));
    }

    /**
     * 修改AGV/CTU执行队列
     */
    @RequiresPermissions("system:execution:edit")
    @GetMapping("/edit/{reqCode}")
    public String edit(@PathVariable("reqCode") String reqCode, ModelMap mmap) {
        AgvExecution agvExecution = agvExecutionService.selectAgvExecutionByReqCode(reqCode);
        mmap.put("agvExecution", agvExecution);
        return prefix + "/edit";
    }

    /**
     * 修改保存AGV/CTU执行队列
     */
    @RequiresPermissions("system:execution:edit")
    @Log(title = "AGV/CTU执行队列", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AgvExecution agvExecution) {
        return toAjax(agvExecutionService.updateAgvExecution(agvExecution));
    }

    /**
     * 删除AGV/CTU执行队列
     */
    @RequiresPermissions("system:execution:remove")
    @Log(title = "AGV/CTU执行队列", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(agvExecutionService.deleteAgvExecutionByReqCodes(ids));
    }
}
